home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / AOCE Utilities / AOCE Snippits / AuthNotification.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-25  |  3.0 KB  |  122 lines  |  [TEXT/MPS ]

  1. /*
  2.  * AuthNotification.c
  3.  * Copyright © 1992 Apple Computer Inc. All Rights Reserved.
  4.  *
  5.  * Manage the notification queue and update our local copy
  6.  * of the current identity when the user locks and unlocks
  7.  * the local identity. Note, it might be better to fetch
  8.  * the local identity each time it is needed, rather than
  9.  * to try to maintain a shadow copy. Perhaps a better example
  10.  * would be to use the notification callback to enable or
  11.  * disable AOCE-specific menu options.
  12.  *
  13.  * Usage:
  14.  *            status = InitNotificationQueue(
  15.  *                        &userIdentity
  16.  *                    );
  17.  */
  18. #include <OCE.h>
  19. #include <OCEAuthDir.h>
  20. #include <OCEErrors.h>
  21. #define TRUE        1
  22. #define FALSE        0
  23.  
  24. OSErr                                InitAuthNotificationQueue(
  25.         LocalIdentity                    *localIdentityPtr
  26.     );
  27. OSErr                                RemoveAuthNotificationQueue(void);
  28.  
  29. static pascal Boolean                MyAuthNotifyProc(
  30.         long                            clientData,
  31.         AuthLocalIdentityOp                callValue,
  32.         AuthLocalIdentityLockAction        actionValue,
  33.         LocalIdentity                    identity
  34.     );
  35.  
  36. /*
  37.  * Initialize the local identity callback.
  38.  */
  39. OSErr
  40. InitAuthNotificationQueue(
  41.         LocalIdentity                *userIdentity
  42.     )
  43. {
  44.         AuthAddToLocalIdentityQueuePB    authParamBlock;
  45.         OSErr                            status;
  46. #define PB    (authParamBlock)
  47.  
  48.         PB.notifyProc = (NotificationProc) MyAuthNotifyProc;
  49.         PB.notifyFlags = (
  50.                 kNotifyLockMask
  51.                 | kNotifyUnlockMask
  52.                 | kNotifyNameChangeMask
  53.             );
  54.         PB.appName = "\pInsert Your Application Name Here";
  55.         PB.clientData = (long) userIdentity;
  56.         status = AuthAddToLocalIdentityQueue(
  57.                     (AuthParamBlockPtr) &authParamBlock,
  58.                     FALSE
  59.                 );
  60.         return (status);
  61. #undef PB
  62. }
  63.  
  64. /*
  65.  * Remove our callback from the local identity queue.
  66.  * Be sure to do this before your application exits:
  67.  * You should trap ExitToShell to make absolutely
  68.  * certain that this function is called.
  69.  */
  70. OSErr
  71. RemoveAuthNotificationQueue(void)
  72. {
  73.         AuthRemoveFromLocalIdentityQueuePB    authParamBlock;
  74.         OSErr                                status;
  75. #define PB    (authParamBlock)
  76.  
  77.         PB.notifyProc = (NotificationProc) MyAuthNotifyProc;
  78.         status = AuthRemoveFromLocalIdentityQueue(
  79.                     (AuthParamBlockPtr) &authParamBlock,
  80.                     FALSE
  81.                 );
  82.         return (status);
  83. #undef PB
  84. }
  85.  
  86. /*
  87.  * Refuse by returning TRUE
  88.  */
  89. static pascal Boolean
  90. MyAuthNotifyProc(
  91.         long                            clientData,
  92.         AuthLocalIdentityOp                callValue,
  93.         AuthLocalIdentityLockAction        actionValue,
  94.         LocalIdentity                    identity
  95.     )
  96. {
  97.         switch (callValue) {
  98.         case kAuthUnlockLocalIdentityOp:
  99.         case kAuthLocalIdentityNameChangeOp:
  100.             /*
  101.              * Store our copy of the local identity.
  102.              * You might, instead, set a flag that
  103.              * causes the application event loop
  104.              * to enable AOCE-specific menu items.
  105.              */
  106.             *((LocalIdentity *) clientData) = identity;
  107.             break;
  108.         default:
  109.         case kAuthLockLocalIdentityOp:
  110.             /*
  111.              * Cancel our copy of the local identity.
  112.              * Here, too, you might prefer setting
  113.              * a flag that causes the application to
  114.              * disable AOCE-specific menu items.
  115.              */
  116.             if (actionValue == kAuthLockWillBeDone)
  117.                 *((LocalIdentity *) clientData) = 0;
  118.             break;
  119.         }
  120.         return (FALSE);            /* We always accept            */
  121. }
  122.